package edu.cqie.smartfarm.exception.handler;

import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import edu.cqie.smartfarm.exception.annotation.GlobalException;
import edu.cqie.smartfarm.exception.exception.IGlobalException;
import edu.cqie.smartfarm.result.R;
import edu.cqie.smartfarm.result.ResultCodeEnum;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 不匹配的输入异常
 *
 * @author shineTan
 * @date 2022/12/26 14:37
 */
@GlobalException(throwable = MismatchedInputException.class)
public class MismatchedInputExceptionHandler implements IGlobalException<R, MismatchedInputException> {

    @Override
    public R exception(MismatchedInputException throwable, HttpServletRequest request, HttpServletResponse response) {
        return BaseThrowExceptionHandler.exception(throwable, ResultCodeEnum.REQUEST_PARAM_ERROR, () ->
                String.format("请求参数类型:%s与实际请求参数类型不匹配", throwable.getTargetType().getSimpleName())
        );
    }
}
